/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.thu.thss.hxd.mazedisplay;



import javafx.scene.DepthTest;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Shear;

  public class Box extends Group {
        final Rotate rx = new Rotate(0,Rotate.X_AXIS);
        final Rotate ry = new Rotate(0,Rotate.Y_AXIS);
        final Rotate rz = new Rotate(0,Rotate.Z_AXIS);
        public int type;//0 no road; 1 road; 2 enter;3 exit
		private Rectangle front;
		private Rectangle top;
		private Rectangle right;
		private Rectangle back;
		private Rectangle left;
		private Rectangle bottom;
        private Paint colorPaint;
       
       /**
         * 
         * @param width
         * @param height
         * @param shearx
         *             /|---------------/
         *            /a|              /
         *           /  |             /
         *          /   |            /
         *         /    |           /
         *        /-----|----------/   如图的错切中，沿x轴错切了，夹角是a，shearx=tan(a).
         * @param color
         * @param shade
         */
        public Box(double width,double height,double shearx, Color color,Color edge, double shade) {
            getTransforms().addAll(rz, ry, rx);
            colorPaint=color.deriveColor(0.0, 1.0, (1 - 0.5*shade), 1.0);
          front = new Rectangle(width, height,color);
            front.setFill(colorPaint);
            
            //top
            double heightTop=width;
            top = new Rectangle(width, heightTop,color);
            Shear shear = new Shear(-shearx, 0);//错切角的tan
            top.getTransforms().add(shear);
            top.setTranslateX(width*shearx);
            top.setTranslateY(-width);
            top.setFill(colorPaint);
            
            right = new Rectangle(width, height,color);
            Shear shearRight = new Shear(0,-1/shearx);//错切角的tan
            right.getTransforms().add(shearRight);
            right.setTranslateX(width);
            right.setFill(colorPaint);

            
            back = new Rectangle(width, height,color);
            back.setFill(colorPaint);
            back.setTranslateX(width*shearx);
            back.setTranslateY(-width);
            
            left = new Rectangle(width, height,color);
            Shear shearLeft = new Shear(0, -1/shearx);//错切角的tan
            left.getTransforms().add(shearLeft);
            left.setFill(colorPaint);

            bottom = new Rectangle(width, heightTop,color);
            Shear shearBottom = new Shear(-shearx, 0);//错切角的tan
            bottom.getTransforms().add(shearBottom);
            bottom.setTranslateX(width*shearx);
            bottom.setTranslateY(-width+height);
            bottom.setFill(colorPaint);
           
            
            getChildren().addAll(back,left,bottom,front,right,top);
            front.setStroke(edge);
            front.setStrokeWidth(1);
            back.setStroke(edge);
            back.setStrokeWidth(1);
            left.setStroke(edge);
            left.setStrokeWidth(1);
            right.setStroke(edge);
            right.setStrokeWidth(1);
            top.setStroke(edge);
            top.setStrokeWidth(1);
            bottom.setStroke(edge);
            bottom.setStrokeWidth(1);
            this.setTranslateZ(20);
            
            this.setDepthTest(DepthTest.ENABLE);
        }

	public Rectangle getFront() {
		return front;
	}

	public void setFront(Rectangle front) {
		this.front = front;
	}

	public Rectangle getTop() {
		return top;
	}

	public void setTop(Rectangle top) {
		this.top = top;
	}

	public Rectangle getRight() {
		return right;
	}

	public void setRight(Rectangle right) {
		this.right = right;
	}

	public Rectangle getBack() {
		return back;
	}

	public void setBack(Rectangle back) {
		this.back = back;
	}

	public Rectangle getLeft() {
		return left;
	}

	public void setLeft(Rectangle left) {
		this.left = left;
	}

	public Rectangle getBottom() {
		return bottom;
	}

	public void setBottom(Rectangle bottom) {
		this.bottom = bottom;
	}

	public Paint getColorPaint() {
		return colorPaint;
	}

	public void setColorPaint(Paint colorPaint) {
		this.colorPaint = colorPaint;
	}
    }

